#pragma once

#include "HSModelAPI.h"
#include "GeometryUtils.h"


class Model3D;
class IObjectForPicker;

#include <memory>


class Picker
  {
  public:
    HSMODEL_API Picker();

    HSMODEL_API size_t AddObject(const IObjectForPicker* ip_object, TVector3 i_position);
    
    // Returns true if exists any intersection with triangle from the World
    HSMODEL_API bool GetIntersectionPoint(TVector3& o_result, const TRay3& i_ray) const;
    
    HSMODEL_API bool GetIntersectionTriangle(TTriangle3& o_triangle, const TRay3& i_ray) const;
    
    HSMODEL_API bool GetIntersectionModelId(size_t& o_index, const TRay3& i_ray) const;

  private:
    bool _GetIntersectionTriangle(TTriangle3& o_triangle, const IObjectForPicker* i_model, const TVector3& i_origin, const TRay3& i_ray) const;
    bool _GetIntersectionInfo(TTriangle3& o_triangle, size_t& o_index, const TRay3& i_ray) const;
  private:
    typedef std::vector<std::pair<const IObjectForPicker*, TVector3>> TObjects;

    TObjects m_for_picking;
  };